package com.zaofan.service;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.zaofan.bean.Feedback;
import com.zaofan.dao.FeedbackDao;
import com.zaofan.exception.ServiceException;
import com.zaofan.utils.WebUtils;

public class FeedbackService {
	private FeedbackDao feedbackDao = new FeedbackDao();

	public void delete(Feedback feedback) {
		feedbackDao.del(feedback);
	}

	public void add(Feedback feedback) throws ServiceException {
		if (WebUtils.isEmpty(feedback.getContent())) {
			throw new ServiceException("请填写您要反馈的问题!!!");
		}
		if (WebUtils.isEmpty(feedback.getMobile())) {
			throw new ServiceException("请填写您的联系电话!!!");

		}
		if (WebUtils.isEmail(feedback.getName())) {
			throw new ServiceException("请填写您的姓名!!!");
		}
		feedback.setAddTime(new Date());
		feedbackDao.add(feedback);
	}

	public void update(Feedback feedback) {
		feedbackDao.update(feedback);
	}

	public List<Feedback> findAll(Map<String, Object> params) {
		List<Feedback> data = feedbackDao.findAll(params);
		if (data == null) {
			data = new ArrayList<>();
		}
		return data;
	}

	public Long count(Map<String, Object> params) {
		return feedbackDao.count(params);
	}

	public Feedback findById(Integer id) {
		Map<String, Object> params = new HashMap<>();
		params.put("id", id);
		return feedbackDao.findOne(params);
	}

}
